﻿using System;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using RIDA.Globals;
using RIDA.DiagramDesigner.ViewModel;
namespace RIDA.DiagramDesigner.Controls
{
    public class DragThumb : Thumb
    {
        public DragThumb()
        {
            base.DragDelta += new DragDeltaEventHandler(DragThumb_DragDelta);
        }

        void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem designerItem = (sender as DragThumb).GetParent<DesignerItem>();
            var vm = designerItem.DataContext as DesignerItemViewModel;
            var left = vm.Left;
            var top = vm.Top;
            left += e.HorizontalChange;
            top += e.VerticalChange;
            vm.Left = Math.Max(0, left);
            vm.Top = Math.Max(0, top);
            e.Handled = true;
        }
    }
}
